//
//  APIClient.swift
//  CodingTest
//
//  Created by LYPC on 2021/11/18.
//

import UIKit
import Alamofire
import HandyJSON
import RxSwift
import RxCocoa
//import RealmSwift

// MARK:- 网络工具

//public enum APIEnvironment {
//    case local(String)  /// 本地
//    case test           /// 测试环境
//    case dev            /// 开发环境
//    case uat
//    case release        /// 发布
//}

//let defalutHeaers = ["Content-Type": "application/json;charset=utf-8",
//                     "X-API-Language": "zh",
//                     "X-API-Version": "1.0",
//                     "X-Client-Type": "iOS",
//                     "X-Client-OS": "iOS",
//                     "X-Client-App-Id": "wq21.wfshwf",
//                     "X-Client-Version": AppInfo.appCurVersion]

//public var headers: [String : String]? {
//    var reqHeaders = defalutHeaers
//    reqHeaders += ["X-Auth-Token": "",
//                   "X-Device-Id": "",
//                   "X-Client-App-Version": AppInfo.appCurVersion]
//    if let otherHeaders = customHeaders {
//        reqHeaders += otherHeaders
//    }
//    return reqHeaders
//}

// MARK: - ********* Public Method
public final class APIClient {

    /// 模拟获取数据
    static func request() -> [DataModel] {

        guard let path = Bundle.main.path(forResource: "data", ofType: "json") else { return [] }
        let localData = NSData.init(contentsOfFile: path)! as Data
        let jsonStr = String(data: localData, encoding: .utf8)
    
        if let responseModel = APIResponseModel.deserialize(from: jsonStr){
            return responseModel.data
        }else{
            return [DataModel()]
        }
    }
}

public typealias FailureHandler = ((_ error: APIResponseError) -> Void)?
